using SharePoint.Security.ConfigAnalyzer.Engine.Base;
using SharePoint.Security.ConfigAnalyzer.Engine.Common;
using Microsoft.SharePoint.Administration;

namespace SharePoint.Security.ConfigAnalyzer.Engine.Rules.Others
{
    public class ManageAccounts : BaseRule
    {
        public ManageAccounts()
        {
            RuleInfo = new RuleInfo
                           {
                               Title = "Managed Accounts",
                               Description = "Ensure that service accounts are registered for Managed accounts (Central administration >  General Security > Configure Managed accounts",
                               ExpectedValue = "> 0"
                           };
        }

        #region Overrides of BaseRule

        public override void Validate()
        {
            var managedAccounts = new SPFarmManagedAccountCollection(ObjectHelper.Farm);

            if (managedAccounts.Count > 0)
            {
                Status = Status.Pass;
            }
            else
            {
                Status = Status.Fail;
            }

            CurrentValue = managedAccounts.Count.ToString();
        }

        #endregion
    }
}